---
title: Setting Up Nginx Server
tags:
- nginx
- web server
- apache
---

   I'm trying out the Nginx web server instead of Apache because
   I've been hearing a lot about how much easier it is to
   configure, and that it's faster etc, etc. I can now say with
   authority, that is not easier to configure, it's harder, but
   it's a good harder, because makes you have more control about
   what you're setting up. So, I'll leave here the server block
   (Nginx version of Virtual Hosts), I made in 28/01/21, for a
   a blog called 'Dazed and Confused':
   ------------------------------------------------------------
   server {
          # Notice that, unlike Apache, you can't have the same
          # port for IPV4 and IPV6. So you'll have to comment it
          # out.
          listen 443 ssl;
          # listen [::]: 443 ssl;

          root /var/www/constantconstipation.club/html/public/;
          # Nginx serves what is described in the index files it
          # finds on the pages.
          index index.html index.htm index.nginx-debian.html;

          server_name constantconstipation.club www.constantconstipation.club;

          location / {
                  try_files $uri $uri/ =404;
          }
          # Nginx wasn't finding the blog folder content, nor it's
          # css structure. So I inserted the 'try_files', and it
          # worked. The line's meaning is this:
          # 'Checks the existence of files in the specified order
          # and uses the first found file for request processing;
          # the processing is performed in the current context.
          # [...]
          # If none of the files were found, an internal redirect
          # to the uri specified in the last parameter is made.'
          location /blogs/ {
                  try_files $uri $uri/ =404;
          }

          # This is what is requested for ssl connection. Mind you,
          # this configuration is being used because, I already had
          # the certbot certificate and needed to change it from an
          # Apache server to Nginx. Probably if you download a
          # certbot version for Nginx, it will do all this
          # configuration for you. But if it doesn't, you can
          # copy/paste from the third row onward and it will run.
          # NOTE: in the last field, 'XSS-Protection', I had to change
          # the double quotes that were to apostrophes, or mysql would
          # respond with an error. If you have any problems, just put
          # double quotes in it.
          ssl_certificate     /etc/letsencrypt/live/constantconstipation.club/fullchain.pem;
          ssl_certificate_key /etc/letsencrypt/live/constantconstipation.club/privkey.pem;
          ssl_protocols TLSv1.2;
          ssl_prefer_server_ciphers on;
          ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
          ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
          ssl_session_timeout  10m;
          ssl_session_cache shared:SSL:10m;
          ssl_session_tickets off; # Requires nginx >= 1.5.9
          ssl_stapling on; # Requires nginx >= 1.3.7
          ssl_stapling_verify on; # Requires nginx => 1.3.7
          resolver 8.8.8.8 8.8.4.4 valid=300s;
          resolver_timeout 5s;
          add_header X-Frame-Options DENY;
          add_header X-Content-Type-Options nosniff;
          add_header X-XSS-Protection '1; mode=block';
   }
   -----------------------------------------------------------------
   The whole process: https://do.co/3t7zmIr
